﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Lagrandje
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }



        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            int width = pictureBox1.Width;
            int height = pictureBox1.Height;
            const int step = 30;
            Font f = Font;

            Graphics g = e.Graphics;

            
            bool firstIteration = true;
            float lastX=0;
            float lastY=0;
            DrawAxes(width, height, f, g, step);
            for (float i = -width/(2*step) ; i <= width/(2*step); i+=(float)0.2)
            {
                float newX;
                float newY;
                newX = i;
                newY = F(i);
                if (firstIteration)
                {
                    lastX = newX;
                    lastY = newY;
                    firstIteration = false;
                    continue;
                }

                g.DrawLine(Pens.Magenta, (lastX*step+width/2), (-lastY*step+height/2),(newX*step+width/2),(-newY*step+height/2));
                
                lastX = newX;
                lastY = newY;
            }
            



        }

        private static void DrawAxes(int width, int height, Font f, Graphics g, int step)
        {
            //draw grid
            int i = 1;
            while (i * step < width / 2 || i*step<height/2)
            {
                g.DrawLine(Pens.White, width / 2 + i * step, 0, width / 2 + i * step, height);
                g.DrawLine(Pens.White, width / 2 - i * step, 0, width / 2 - i * step, height);
                g.DrawLine(Pens.White, 0, height / 2 + i * step, width, height / 2 + i * step);
                g.DrawLine(Pens.White, 0, height / 2 - i * step, width, height / 2 - i * step);
                i++;
            }

            //draw x axis
            g.DrawLine(Pens.Black, 0, height / 2, width, height / 2);
            g.DrawLine(Pens.Black, width, height / 2, width - 15, height / 2 - 3);
            g.DrawLine(Pens.Black, width, height / 2, width - 15, height / 2 + 3);
            g.DrawString("X", f, Brushes.Red, width - 30, height / 2 + 10);
            g.DrawLine(Pens.Black, width / 2+step, height/2-4, width / 2+step, height/2+4);

            //draw y axis
            g.DrawLine(Pens.Black, width / 2, 0, width / 2, height);
            g.DrawLine(Pens.Black, width / 2, 0, width / 2 - 3, 15);
            g.DrawLine(Pens.Black, width / 2, 0, width / 2 + 3, 15);
            g.DrawString("Y", f, Brushes.Red, width/2  +10, 10);

            


        }

        private float F(float x)
        {
            return x * x*x;

           
        }

        #region bull shit
        private void Form1_Resize(object sender, EventArgs e)
        {
            pictureBox1.Width = Width;
            pictureBox1.Height = Height;

            pictureBox1.Invalidate();
        }
        #endregion
    }
}
